﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace LogFileScanner
{
    public partial class HelpViewer : DockContent, LogFileScanner.Viewer
    {
        public HelpViewer()
        {
            InitializeComponent();
        }


        #region Public Interface

        public event Utility.VoidMethodDelegate NotifyProgressStart;
        public event Utility.VoidMethodDelegate NotifyProgressStop;
        public event Utility.MessageMethodDelegate NotifyLogMessage;

        public void Terminate()
        {
        }

        public void LoadOnlineHelp()
        {
            webBrowser.Navigate(Properties.Settings.Default.HelpURL);
        }

        public void LoadOfflineHelp()
        {
            string helpHtml = LogFileScanner.Properties.Resources.Help;
            helpHtml = ReplaceTags(helpHtml);
            webBrowser.DocumentText = helpHtml;
        }

        public void LoadHelp()
        {
            if (!webBrowser.IsOffline)
            {   
                LoadOnlineHelp();
            }
            else
            {
                LoadOfflineHelp();
            }
        }
        
        #endregion

        private string ReplaceTags(string helpHtml)
        {
            helpHtml = helpHtml.Replace("${product}", AboutBox.AssemblyProduct);
            helpHtml = helpHtml.Replace("${version}", AboutBox.AssemblyVersion);
            helpHtml = helpHtml.Replace("${company}", AboutBox.AssemblyCompany);
            helpHtml = helpHtml.Replace("${description}", AboutBox.AssemblyDescription);
            helpHtml = helpHtml.Replace("${copyright}", AboutBox.AssemblyCopyright);

            helpHtml = helpHtml.Replace("${web.url}", Properties.Settings.Default.HelpURL);
            return helpHtml;
        }

        private void HelpViewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
        }
        
        private void HelpViewer_Activated(object sender, EventArgs e)
        {
            LoadHelp();
        }

        private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {

        }

        private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {

        }

        private void webBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
        {
            
        }
    }
}
